<?php

/**
 * login actions.
 *
 * @package    development_symfony
 * @subpackage login
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class loginActions extends sfActions {

    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
  
    public function executeIndex(sfWebRequest $request) {
//        $this->getUser()->setCulture('en_US');
        $this->formlogin = new AccountForm(null, array('action' => 'login'));
        if ($request->getPostParameter('lg')) {
//            $test = '<script>alert("ok")</script>';
//            echo $test;

            if ($request->getParameter('remember')) {
                $this->processAction($request, $this->formlogin, array('action' => 'login', 'remember' => true));
            } else {
                $this->processAction($request, $this->formlogin, array('action' => 'login', 'remember' => false));
            }
        } else {
            
        }
//        $memcache = new Memcache;
//
//        $memcache->connect("localhost", 11211); # You might need to set "localhost" to "127.0.0.1"
//
//        echo "Server's version: " . $memcache->getVersion() . "<br />\n";
//
//        $tmp_object = new stdClass;
//
//        $tmp_object->str_attr = "test";
//
//        $tmp_object->int_attr = 123;
//
//        $memcache->set("key", $tmp_object, false, 10);
//
//        echo "Store data in the cache (data will expire in 10 seconds)<br />\n";
//
//        echo "Data from the cache:<br />\n";
//
//        var_dump($memcache->get("key"));
    }

    public function executeLogout() {
//        sfView::NONE;
        $this->getUser()->setAuthenticated(false);
        $this->redirect('login');
    }

    public function executeListuser() {
        $this->listuser = AccountPeer::getListUser();
    }

    protected function processAction(sfRequest $request, sfForm $form, $option) {
        $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
        if ($form->isValid()) {
            if ($option['action'] === 'login') {
                if (AccountPeer::login($request->getParameter($form->getName())) === true) {
                    $this->processLogin($option['remember']);
                    $this->redirect("/");
                }
            }
            if ($option['action'] === 'register') {
                if ($form->isValid()) {
                    $form->save();
                    $this->getUser()->setFlash('msg', 'Dang ki thanh cong');
                    $this->redirect('/login');
                }
            }

//            echo print_r($request->getParameter($form->getName()));
//            echo print_r(AccountPeer::login($request->getParameter($form->getName())));
        }
    }

    public function executeRegister(sfRequest $request) {
        $this->form = new AccountForm(null, array('action' => 'register'));
        if ($request->getParameter('act') === 'register') {
            $this->processAction($request, $this->form, array('action' => 'register'));
        }
    }

    public function executeView(sfRequest $request) {
//        $idd=$request->getParameter('id');
//       
//        $acccc=  AccountPeer::getAccount($idd);
        $acccc=$this->getRoute()->getObject();
        $this->form=new AccountForm($acccc);
    }

    public function executeDelete(sfRequest $request) {
        $request->checkCSRFProtection();

        $criteria = new Criteria();
        $criteria->add(AccountPeer::ID, $request->getParameter('id'));
        $acc = AccountPeer::getAccount($criteria);
        $acc->delete();
//        $this->setTemplate('listuser');
        $this->redirect('/list');
    }

    protected function processLogin($remember) {
        if ($remember == true) {
            $this->getResponse()->setCookie('user', 'test', time() + 60);
            $this->getUser()->setAuthenticated(true);
            $this->getUser()->setAttribute('username', 'test');
        } else {
            $this->getUser()->setAuthenticated(true);
            $this->getUser()->setAttribute('username', 'test');
        }
    }
	
	public function executeHienthi(sfRequest $request)
	{
	
	 echo "i will merger file before commit but i dont think i cant merge"
	}

	public function executeNoichuoi()
	{
	echo "hien thi thong tin "
	}
	
	ok
	public func tion then gi do
	{
	adsasdas
	}
	s
	sdsdsds
	
	
	public function honnaythemfunction 3()
	{
	     $this->form=new sfForm()
		 $this->form->bind($request->getParemeter($this->form->getName()))
		 {
		     if($form->isValid())
			 {
			 form->save();
			 }
		 }
		 }
	
	  
	}

	public function thenthangthu5555()
	{
	echo "toiu moi them dong nay vaof day nayf"
	}
	
	public function then thang thu 3
	{
	echo "sdsd";
	}
	
	public function themthangthu10
	{
	}
	punlic function themthang4
	{
	echo 4
	echo4
	echo 8 
	echo 8
	echo 8
	echo 4
	echo6
	testthem te
	te
	echo18
	echo 18
	
	
}
